package condition;

import java.util.Iterator;
import java.util.Set;

import roborally.Direction;
import elements.Element;
import elements.Robot;
import elements.Wall;

/**
 * A class of unary basic conditions.
 * 
 * @version	3.0
 * @author 	Lies Tambeur 	r0264469	2Bcwsbbh
 * @author	Eline Vanrykel	r0264543	2Bcwselt
 *
 */
public class WallCondition extends UnaryBasicCondition {

	/**
	 * Returns true only if the element has an orientation and if
	 * there is a wall located to the right of the element.
	 */
	@Override
	public boolean evaluate(Element element) {
		if(element instanceof Robot){
			Set<Element> elements = element.getBoard().getElements(element.getPosition().getNeighbour(((Robot)element).getOrientation().turn(Direction.CLOCKWISE)));
			if(elements.size()!=0){
				Iterator<Element> it = elements.iterator();
				while(it.hasNext()){
					Element itelement = it.next();
					if(itelement instanceof Wall){
						return true;
					}
				}
				return false;
		}
			else{
				return false;
			}
		}
		else{
			return false;
		}

	}
	
	@Override
	public String toString(){
		return "(wall)";
	}
	
	@Override
	public boolean equals(Object object){
		if(object == null || this==null){
			return false;
		}
		return this.toString().equals(object.toString());
	}

}
